package com.riber.student.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author: Riber
 * @date: 2022/10/25 22:26
 * @description:
 */
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        //设置什么请求映射的路径需要处理跨域,项目任何请求映射路径
        registry.addMapping("/**")
                //任意请求的内容都可以放行
                .allowedHeaders("*")
                //任意方式都可以 get post delete put
                .allowedMethods("*")
                //任意站点过来的请求都放行
                .allowedOriginPatterns("*")
                //允许 状态标识的传输 cookie
                .allowCredentials(true);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyAuthorizationInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/login");
    }
}
